<template>
	<view class="container">
		<tui-input @click="hospitalSelect" v-model="patient.hospital_id_text" label="所属研究中心：" :disabled="true" placeholder="请输入所属研究中心"></tui-input>
		<tui-select :multiple="false" :list="list" :show="show" @confirm="confirm" @close="onClose"></tui-select>
		<tui-input v-model="patient.name" label="姓名：" placeholder="请输入姓名"></tui-input>
		<radio-group class="radio-group" name="sex" @change="genderChange">
			<label>性别：</label>
			<label class="tui-radio">
				<radio value="1" :checked="patient.gender == 1" color="#5677fc" ></radio>男
			</label>
			<label class="tui-radio">
				<radio value="2" :checked="patient.gender == 2" color="#5677fc" ></radio>女
			</label>
		</radio-group>
		<tui-input v-model="patient.birth_date" label="出生日期：" placeholder="请输入出生日期"></tui-input>
		<tui-input v-model="patient.contact" label="联系方式：" placeholder="请输入联系方式"></tui-input>
		<tui-input v-model="patient.native_place" label="籍贯：" placeholder="请输入籍贯"></tui-input>
		<tui-input v-model="patient.weight" label="体重(kg)：" placeholder="请输入体重(kg)"></tui-input>
		<tui-input v-model="patient.height" label="身高(cm)：" placeholder="请输入身高(cm)"></tui-input>
		<tui-input v-model="patient.current_residence" label="现居地：" placeholder="请输入现居地"></tui-input>
		<tui-input v-model="patient.hospital_name" label="救治医院名称：" placeholder="请输入救治医院名称"></tui-input>
		<tui-input v-model="patient.hospital_province" label="救治医院所在省份：" placeholder="请输入救治医院所在省份"></tui-input>
		<tui-input v-model="patient.hospital_level_text" label="救治医院等级：" placeholder="请输入救治医院等级"></tui-input>
		<tui-input v-model="patient.treatment_mode" label="治疗模式：" placeholder="请输入治疗模式"></tui-input>
		<tui-list-cell>
			<view class="thorui-flex__between">
				<text>在医院有烧伤科 (无/有)：</text>
				<tui-switch @change="hasBurnDepartmentChange" :checked="patient.has_burn_department"></tui-switch>
			</view>
		</tui-list-cell>
		<tui-list-cell>
			<view class="thorui-flex__between">
				<text>在医院有烧伤重症监护室 (无/有)：</text>
				<tui-switch @change="hasBurnIcuChange" :checked="patient.has_burn_icu"></tui-switch>
			</view>
		</tui-list-cell>
		<tui-list-cell>
			<tui-form-button v-on:click="sure()" height="2.6" radius="50px">确定</tui-form-button>
		</tui-list-cell>
	</view>
</template>

<script>
	import tuiInput from "@/components/thorui/tui-input/tui-input.vue"
	import tuiFormButton from "@/components/thorui/tui-form-button/tui-form-button.vue"	
	import tuiRadio from "@/components/thorui/tui-radio/tui-radio.vue"
	import tuiRadioGroup from "@/components/thorui/tui-radio-group/tui-radio-group.vue"
	import tuiSelect from "@/components/thorui/tui-select/tui-select.vue"
	export default {
		components: {
			tuiRadio,
			tuiRadioGroup,
			tuiInput,
			tuiFormButton,
			tuiSelect
		},
		data() {
			return {
				patientId: 0,
				hospitalList: [],
				patient: {},
				injuryList: {},

				show: false,
				list: [],
			}
		},
		onLoad(options) {
			this.patientId = options.id;
			this.http.get("/api/patient/detail?id=" + this.patientId)
				.then(res => {
					this.patient = res.data.data.patient;
					this.injuryList = res.data.data.injuryList;
				})
				.catch(err => {
					
				})
			this.http.get("/api/hospital/list?page=1&size=1000")
				.then(res => {
					if(res.data.code == 1) {
						this.hospitalList = res.data.data;
						this.hospitalList.forEach((item, index) => {
							this.list = [...this.list, {
								text: item.name,
								value: item.id,
								checked: item.id == this.patient.hospital_id ? true : false
							}];
						})
					}
				})
				.catch(err => {

				})
		},
		methods: {
			sure() {
				this.http.post("/api/patient/add", {
					data: this.patient
				})
					.then(res => {
						console.log(res)
					})
					.catch(err => {
						
					})
			},
			genderChange(e) {
				this.patient.gender = e.detail.value;
			},
			hasBurnDepartmentChange(e) {
				this.patient.has_burn_department = e.detail.value == true ? 1 : 0;
			},
			hasBurnIcuChange(e) {
				this.patient.has_burn_icu = e.detail.value == true ? 1 : 0;
			},
			//调用此方法显示选择弹框
			showSelect() {
				this.show = true
			},
			confirm(e) {
				this.patient.hospital_id_text = this.list[e.index].text;
				this.patient.hospital_id = this.list[e.index].value;
				this.onClose()
			},
			onClose() {
				this.show = false
			},
			hospitalSelect() {
				this.show = true;
			}
		}
	}
</script>

<style scoped>
	@import '@/static/style/thorui-extend.css';
	.container {
		padding-top: 30rpx;
		background-color: white;
	}
	.thorui-align__center {
		display: flex;
		align-items: center;
	}
	.tui-text {
		font-size: 30rpx;
		padding-left: 12rpx;
	}
	.radio-group {
		font-size: 32rpx;
		line-height: 98rpx;
		margin-left: 30rpx;
	}
	.thorui-flex__between text {
		font-size: 32rpx;
		margin-left: 0rpx;
		padding-left: 0rpx;
	}
</style>
